package com.ss.demo.springbootdemo.ex;

import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 作者: MrZhangJR
 * 时间: 2021/11/3 15:28
 * 描述:
 */
@RestControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Object commException(Throwable e) {
        e.printStackTrace();
        System.out.println("500服务器运行异常");
        return "failed";
    }

    @ExceptionHandler(ArithmeticException.class)
    public Object arithmeticExceptionException(Throwable e) {
        e.printStackTrace();
        System.out.println("500运算异常");
        return "failed";
    }

    @ExceptionHandler(MyException.class)
    public Object myException(Throwable e) {
        e.printStackTrace();
        System.out.println("自定义异常");
        // todo 这块儿也可以定义统一返回值
        return "failed";
    }
}
